﻿using System.Collections.Generic;
using Rodunu.Business.Interfaces;
using Rodunu.Business.Models.User;

namespace Rodunu.Business.Logic
{
    public class ManageUser : IManageUser
    {
        private readonly IManageSettings _manageSettings;

        public ManageUser(IManageSettings manageSettings)
        {
            _manageSettings = manageSettings;
        }

        #region IManageUser Members

        public bool CreateUser(User newUser, bool rememberUser, bool rememberPassword, bool autoLogIn)
        {
            IList<User> users = new List<User>();
            if (_manageSettings.CurrentSettings.Users != null)
            {
                foreach (var user in _manageSettings.CurrentSettings.Users)
                {
                    users.Add(user);
                }
            }

            users.Add(newUser);

            _manageSettings.CurrentUser = newUser;

            _manageSettings.CurrentSettings.Users = users;
            _manageSettings.CurrentSettings.LastUserLoggedIn = newUser.UserName;

            _manageSettings.CurrentSettings.AutoLogin = autoLogIn;
            _manageSettings.CurrentSettings.RememberMe = rememberUser;
            _manageSettings.CurrentSettings.RememberPassword = rememberPassword;

            _manageSettings.SaveCurrentSettings();

            return true;
        }

        #endregion
    }
}
